import type {
  DoctorPage,
  knowledgePage,
  knowledgeParams,
  pageParams,
  FollowType,
  Follow,
  TopDep,
  Image,
  ConsultOrderPreParams,
  ConsultOrderPreData,
  PartialConsult,
  pay,
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage
} from '@/types/consult'

import { request } from '@/utils/request'

export const getKnowledgePage = (params: knowledgeParams) =>
  request<knowledgePage>('/patient/home/knowledge', 'GET', params)
export const getDoctor = (params: pageParams) =>
  request<DoctorPage>('/home/page/doc', 'GET', params)

// 关注医生
export const FollowOrUnfollow = (id: string, type: FollowType = 'doc') =>
  request<Follow>('/like', 'POST', {
    id,
    type
  })

// 请求一级科室
export const getAllDep = () => request<TopDep[]>('/dep/all')
// 上传图片
export const upLoadImage = (file: File) => {
  // FormData对象
  const fd = new FormData()
  // ‘需要的参数key’ ,上传的文件
  fd.append('file', file)
  return request<Image>('/upload', 'POST', fd)
}

// 请求预订单
export const getConsultOrderPre = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)

// 生成问诊订单信息 --请求参数之前已经定义好了
export const createConsultOrder = (params: PartialConsult) =>
  request<{ id: string }>('/patient/consult/order', 'POST', params)

// 发起支付请求
export const getConsultOrderPayUrl = (params: pay) =>
  request<{ payUrl: string }>('/patient/consult/pay', 'POST', params)
// 获取问诊记录
export const getConsultOrderDetail = (orderId: string) =>
  request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', { orderId })
// 预览处方图片
export const getPrescriptionPic = (id: string) =>
  request<{ url: string }>(`/patient/consult/prescription/${id}`, 'GET', { id })
export const evaluateConsultOrder = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 1 | 0
}) => request<{ id: string }>('/patient/order/evaluate', 'POST', data)

export const getConsultOrderList = (params: ConsultOrderListParams) =>
  request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)

export const cancelOrder = (id: string) =>
  request(`/patient/order/cancel/${id}`, 'PUT')

export const deleteOrder = (id: string) =>
  request(`/patient/order/${id}`, 'DELETE')
